package com.ruoyi.house_sale.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.house_sale.domain.WorkProcess;
import com.ruoyi.house_sale.service.IWorkProcessService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 办理进度Controller
 *
 * @author ruoyi
 * @date 2022-04-08
 */
@RestController
@RequestMapping("/house_sale/WorkProcess")
public class WorkProcessController extends BaseController
{
    @Autowired
    private IWorkProcessService workProcessService;

    /**
     * 查询办理进度列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:WorkProcess:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkProcess workProcess)
    {
        startPage();
        List<WorkProcess> list = workProcessService.selectWorkProcessList(workProcess);
        return getDataTable(list);
    }

    /**
     * 导出办理进度列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:WorkProcess:export')")
    @Log(title = "办理进度", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkProcess workProcess)
    {
        List<WorkProcess> list = workProcessService.selectWorkProcessList(workProcess);
        ExcelUtil<WorkProcess> util = new ExcelUtil<WorkProcess>(WorkProcess.class);
        util.exportExcel(response, list, "办理进度数据");
    }

    /**
     * 获取办理进度详细信息
     */
    @PreAuthorize("@ss.hasPermi('house_sale:WorkProcess:query')")
    @GetMapping(value = "/{processid}")
    public AjaxResult getInfo(@PathVariable("processid") Long processid)
    {
        return AjaxResult.success(workProcessService.selectWorkProcessByProcessid(processid));
    }

    /**
     * 新增办理进度
     */
    @PreAuthorize("@ss.hasPermi('house_sale:WorkProcess:add')")
    @Log(title = "办理进度", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkProcess workProcess)
    {
        workProcess.setOprtime(new Date());
        workProcess.setUserid(SecurityUtils.getUsername());
        return toAjax(workProcessService.insertWorkProcess(workProcess));
    }

    /**
     * 修改办理进度
     */
    @PreAuthorize("@ss.hasPermi('house_sale:WorkProcess:edit')")
    @Log(title = "办理进度", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkProcess workProcess)
    {
        return toAjax(workProcessService.updateWorkProcess(workProcess));
    }

    /**
     * 删除办理进度
     */
    @PreAuthorize("@ss.hasPermi('house_sale:WorkProcess:remove')")
    @Log(title = "办理进度", businessType = BusinessType.DELETE)
    @DeleteMapping("/{processids}")
    public AjaxResult remove(@PathVariable Long[] processids)
    {
        return toAjax(workProcessService.deleteWorkProcessByProcessids(processids));
    }
}
